package com.huawei.dli.flink.sye.utils;

import org.apache.kafka.clients.producer.Partitioner;
import org.apache.kafka.common.Cluster;

import java.util.Map;
import java.util.Random;

/**
 * @author joker
 * @program: dli-flink-demo
 * @description:  kafka 自定义分区   类中设置，但可能没起作用 todo
 * @Version joker
 * @Modified joker
 * @date 2020-08-21 19:52:51
 */
public class CustomerPartition implements Partitioner {
    /**
     * 业务逻辑
     * @param topic
     * @param key
     * @param valueBytes
     * @param value
     * @param keyBytes
     * @param cluster
     * @return
     */
    @Override
    public int partition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, Cluster cluster) {
      /*  List<PartitionInfo> partitions = cluster.partitionsForTopic(topic);
        String string = JSONArray.toJSONString(valueBytes);
*/
        Random random = new Random();
        int i = random.nextInt(12);
        System.out.println("i = " + i);
        return i;
    }


    @Override
    public void close() {

    }

    @Override
    public void configure(Map<String, ?> map) {

    }
}
